package com.tjn.thread;

/**
 * @author 陶镓妮
 * @version 1.0
 */
public class Thread03 {
    public static void main(String[] args) {
        Hello hello = new Hello();
        Hi hi = new Hi();
        Thread thread1 = new Thread(hello);
        Thread thread2 = new Thread(hi);
        thread1.start();
        thread2.start();
    }
}

class Hello implements Runnable{
    @Override
    public void run() {
        int count = 0;
        while(true){
            System.out.println("hello world  " + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(count == 10){
                break;
            }
        }
    }
}
class Hi implements Runnable{
    @Override
    public void run() {
        int count = 0;
        while(true){
            System.out.println("hi  " + (++count));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            if(count == 5){
                break;
            }
        }
    }
}